package cn.dxh.stagefinal.controller;

import cn.dxh.stagefinal.bean.Company;
import cn.dxh.stagefinal.bean.Department;
import cn.dxh.stagefinal.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * IntelliJ IDEA -> stagefinal
 * 2019/12/9 21:17
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Controller
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @RequestMapping("/record/insertcompany.html")
    public String insert(){
        return  "record/insertcompany";
    }

    @RequestMapping("/record/insertCom.do")
    public  void  insertCompany(Company company, HttpServletResponse response){
        try {
            int len = companyService.insertCompany(company);
            response.setContentType("text/html;charset= utf-8");
            PrintWriter out= response.getWriter();
            if (len > 0 ){
                out.println("<script> alert('公司添加成功');location.href='/right'</script>");
            }
            else {
                out.println("<script> alert('公司添加失败');location.href='/record/insertcompany.html';</script>");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/record/companydesc.html")
    public String   companydesc(){
        return  "/record/companydesc";
    }
}